//===============================================================================
// Microsoft patterns & practices
// Web Client Software Factory
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.ObjectModel;
using System.Globalization;
using Microsoft.Practices.CompositeWeb;
using Microsoft.Practices.ObjectBuilder;
using Microsoft.Practices.CompositeWeb.Web;
using WCSFContrib.ECommerceCatalog.Product.Services;
using WCSFContrib.ECommerceCatalog.BusinessEntities;
using WCSFContrib.ECommerceCatalog.User.Interfaces.Services;
using WCSFContrib.ECommerceCatalog.Product.Interfaces.Services;

namespace WCSFContrib.ECommerceCatalog.Product
{
    public class ProductController : IProductController
    {
        private IItemsService _itemsService;
        private ICategoriesService _categoriesService;
        private ICartService _cartService;
        private INavigationService _navigationService;

        [InjectionConstructor]
        public ProductController([ServiceDependency] IItemsService itemsService,
                                 [ServiceDependency] ICategoriesService categoriesService,
                                 [ServiceDependency] ICartService cartService,
                                 [ServiceDependency] INavigationService navigationService)
        {
            _itemsService = itemsService;
            _categoriesService = categoriesService;
            _cartService = cartService;
            _navigationService = navigationService;
        }

        public ProductController()
        { }

        protected IItemsService ItemsService
        {
            get { return _itemsService; }
        }

        protected ICategoriesService CategoriesService
        {
            get { return _categoriesService; }
        }

        protected ICartService CartService
        {
            get { return _cartService; }
        }

        protected INavigationService NavigationService
        {
            get { return _navigationService; }
        }

        #region IProductController Members

        public Item GetProduct(int productId)
        {
            Item product = _itemsService.GetItemById(productId);
            return product;
        }

        public ICollection<Item> SearchProducts(string searchText)
        {
            ICollection<Item> products = _itemsService.SearchItems(searchText);
            return products;
        }

        public void GoCartPage()
        {
            _navigationService.GoCart();
        }

        public void AddProductToCart(string userName, int itemId, int quantity)
        {
            _cartService.AddItem(userName, itemId, quantity);
        }

        #endregion
    }
}
